package com.springboot.dao.mapper;

import com.springboot.model.ProductCategory;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

/**
 * 使用注解方式 实现增删改查
 */
@Mapper
public interface ProductCategoryMapper {

    @Select("select s.category_id as categoryId ,s.category_name as categoryName ,s.category_type as categoryType from product_category s where s.category_type =#{categoryType}")
    ProductCategory findByCategoryType(Integer categoryType);

    /**
     * 如果你的映射方法的形参有多个，这个注解使用在映射方法的参数上就能为它们取自定义名字。
     * 若不给出自定义名字，多参数（不包括 RowBounds 参数）则先以 "param" 作前缀，再加上它们的参数位置作为参数别名。
     * 例如 #{param1}, #{param2}，这个是默认值
     * @param param1
     * @param param2
     * @return
     */
    @Select("select s.category_id,s.category_name,s.category_type from product_category s where s.category_name=#{param1}  and s.category_type =#{param2}")
    List<ProductCategory> findByCategoryNameAndType(String param1, String param2);

    @Select("select s.category_id,s.category_name,s.category_type from product_category s where s.category_name=#{categoryName}  and s.category_type =#{categoryType}")
    List<ProductCategory> findByObject(ProductCategory productCategory);

    @Select("select s.category_id,s.category_name,s.category_type from product_category s where s.category_name=#{categoryName}  and s.category_type =#{categoryType}")
    @Results(id = "caibixiang", value = {@Result(column = "category_name", property = "categoryName"), @Result(column = "category_type", property = "categoryType")})
    List<ProductCategory> findByMap(Map<String, Object> map);

    @Insert("insert into product_category(category_name,category_type) values(#{categoryName},#{categoryType})")
    int addProductCategory(ProductCategory productCategory);

    @Update("update product_category s set s.category_name=#{categoryName}, s.category_type=#{categoryType} where s.category_id=#{categoryId}")
    int updateProductCategory(ProductCategory productCategory);

    @Delete("delete from product_category  where category_id=#{id} ")
    int deleteProductCategoryById(Integer ids);


    List<ProductCategory> findByProductCategory(ProductCategory productCategory);

}
